﻿/*----------------------------------------------------------------
// Copyright (C) 2009 
// 版权所有。 
//
// 文件名：
// 文件功能描述：个人考勤信息统计
//
//
// 创建标识：
// 程序作者：翟允锋
// 修改标识：
// 修改描述：
//----------------------------------------------------------------*/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using EQT.Dal;
using System.Threading;
using EQT.Model;
using Wuqi.Webdiyer;
using Common.Logging;

public partial class TimeRecordPerson : System.Web.UI.Page
{
    private static readonly ILog log = LogManager.GetCurrentClassLogger();
    private DaActLog daLog = DevFuture.Common.WorkContext.AppCtx.GetObject("DaActLog") as DaActLog;
    private UserContext context;

    protected void Page_Load(object sender, EventArgs e)
    {
        context = Session["USER_CONTEXT"] as UserContext;
        OperationResult.Text = "";
        divResult.Visible = false;
        if (!IsPostBack)
        {
            //登陆模拟.
            //Session.Add("UID", "U0004");

            for (int i = DateTime.Now.Year - 2; i <= DateTime.Now.Year; i++)
            {
                DdlYear.Items.Add(new ListItem(i.ToString()+"年",i.ToString()));
            }
            DdlYear.SelectedValue = string.Format("{0:D4}", DateTime.Now.Year);

            for (int i = 1; i <= 12; i++)
            {
                DdlMonth.Items.Add(new ListItem(i.ToString() + "月份", string.Format("{0:D2}", i)));
            }

            DdlMonth.Items.Insert(0, new ListItem("全部", ""));
            DdlMonth.SelectedValue = "";
            this.BtnQuery_Click(null, null);
        }
    }

    protected void BtnQuery_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < GridView.Columns.Count; i++)
        {
            GridView.Columns[i].Visible = true;
        }
        
        DataSet dsRecords ;

        if (string.IsNullOrEmpty(DdlMonth.SelectedValue))
        {
            dsRecords = daLog.GetTimeBookByUserPerYear(DdlYear.SelectedValue,context.UserID);
        }
        else
        { 
            dsRecords=daLog.GetTimeBookByUserPerMonth(DdlYear.SelectedValue+DdlMonth.SelectedValue, context.UserID);
        }

        this.GridView.DataSource = dsRecords;

        GridView.DataBind();

        if (dsRecords.Tables[0].Rows.Count > 0)
        {
            int days =string.IsNullOrEmpty(DdlMonth.SelectedValue)?31: DateTime.DaysInMonth(DateTime.Now.Year, int.Parse(DdlMonth.SelectedValue));

            for (int i = 4; i < 35; i++)
            {
                if (string.IsNullOrEmpty(DdlMonth.SelectedValue))
                {
                    GridView.HeaderRow.Cells[i].Text = Convert.ToString(i - 3) + "日";
                }
                else
                {
                    GridView.HeaderRow.Cells[i].Text = int.Parse(DdlMonth.SelectedValue).ToString() + "月" + Convert.ToString(i - 3) + "日<br/>" +
                        ServerValidate.GetWeekDay(DateTime.Now.Year.ToString() + "-" + int.Parse(DdlMonth.SelectedValue).ToString() + "-" + Convert.ToString(i - 3));
                }

                GridView.HeaderRow.Cells[i].HorizontalAlign = HorizontalAlign.Center;
                GridView.HeaderRow.Cells[i].Width = 60;
                GridView.HeaderRow.Cells[i].ForeColor = System.Drawing.Color.White;
            }

            for (int i = 31; i > days; i--)
            {
                GridView.Columns[3 + i].Visible = false;
            }

            GridView.Width = 2400;
        }
    }
}
